<?php

class Application_Model_Menu
{
private $menus = array();
	private $submenus = array();
	private $enlaces = array();
	private $id = array();
	
	public function __construct()
	{		
		
	}
	
	public function setMenu($menu)
	{
		$this->menus[] = $menu;
	}
	
	public function setSubmenu($menu, $submenu, $id, $enlace ='')
	{
		if(is_string($menu)){
			$key = array_search($menu, $this->menus);
			//Añadimos el submenú
			$this->submenus[$key][] = $submenu;
			//Añadimos el código
			$this->id[$key][] = $id;
			//Añadimos el enlace
			$this->enlaces[$key][] = $enlace;
		}
	}
	
	public function render()
	{
		$menus = $this->getMenus();
        $html = '';
        foreach ($menus as $key => $value) {
        	$submenus = $this->getSubmenu($key);
        	
        	unset($link);
        	foreach ($submenus as $key2 => $value2) {
        		$enlace = $this->getEnlace($key, $key2);
        		$id = $this->id[$key][$key2];
        		$link[] = "<li><a id='$id' href='$enlace'>".$value2."</a></li>
        				    ";
        	}
        	$string = implode("", $link);
        	$html .= "<div>
                      	<div style='margin-top: 2px;'>
                       		<div style='margin-left: 4px; float: left;'>
                            	".$value."
                            </div>
                        </div>
                      </div>
                      <div>
                      	<ul>
                        	$string
                        </ul>
                     </div>
                     ";
        }
        return $html;
	}
	
	public function getMenus()
	{
		return $this->menus;
	}
	
	public function getSubmenu($idMenu)
	{
		return $this->submenus[$idMenu];
	}
	
	public function getEnlace($idMenu, $idSubMenu)
	{
		$enlace = $this->enlaces[$idMenu][$idSubMenu];
		if($enlace == '') $enlace = '#';
		return $enlace;
	}

}

